home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / bbs_util / bsrc_260.zip / SRC.ZIP / B_FUSER.C < prev    next >
C/C++ Source or Header  |  1996-02-20  |  6KB  |  148 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*              (C) Copyright 1987-96, Bit Bucket Software Co.              */
  11. /*                                                                          */
  12. /*                  This module was written by Bob Hartman                  */
  13. /*                                                                          */
  14. /*                  BinkleyTerm Fidolist processing module                  */
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*    For complete  details  of the licensing restrictions, please refer    */
  18. /*    to the License  agreement,  which  is published in its entirety in    */
  19. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.260.    */
  20. /*                                                                          */
  21. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  22. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  23. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  24. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  25. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  26. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  27. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  28. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  29. /*                                                                          */
  30. /*                                                                          */
  31. /* You can contact Bit Bucket Software Co. at any one of the following      */
  32. /* addresses:                                                               */
  33. /*                                                                          */
  34. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  35. /* P.O. Box 460398                AlterNet 7:42/1491                        */
  36. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  37. /*                                Internet f491.n343.z1.fidonet.org         */
  38. /*                                                                          */
  39. /* Please feel free to contact us at any time to share your comments about  */
  40. /* our software and/or licensing policies.                                  */
  41. /*                                                                          */
  42. /*--------------------------------------------------------------------------*/
  43.  
  44. /* Include this file before any other includes or defines! */
  45.  
  46. #include "includes.h"
  47.  
  48. static int reclength = -1;
  49. static int nrecs = -1;
  50.  
  51. void 
  52. fidouser (char *name, ADDRP faddr)
  53. {
  54.     int low, high, mid, f, cond, namelen;
  55.     char midname[80];
  56.     char last_name_first[80];
  57.     char *c, *p, *m;
  58.     struct stat buffer;
  59.  
  60.     faddr->Zone = faddr->Net = faddr->Node = faddr->Point = (unsigned short) -1;
  61.     faddr->Domain = NULL;
  62.  
  63.     c = midname;                                /* Start of temp name buff  */
  64.     p = name;                                    /* Point to start of name   */
  65.     m = NULL;                                    /* Init pointer to space    */
  66.  
  67.     *c = *p++;
  68.     while (*c)                                    /* Go entire length of name */
  69.     {
  70.         if (*c == ' ')                            /* Look for space           */
  71.             m = c;                                /* Save location            */
  72.         c++;
  73.         *c = *p++;
  74.     }
  75.  
  76.     if (m != NULL)                                /* If we have a pointer,    */
  77.     {
  78.         *m++ = '\0';                            /* Terminate the first half */
  79.         (void) strcpy (last_name_first, m);        /* Now copy the last name   */
  80.         (void) strcat (last_name_first, ", ");    /* Insert a comma and space */
  81.         (void) strcat (last_name_first, midname);/* Finally copy first half */
  82.     }
  83.     else
  84.         (void) strcpy (last_name_first, midname);/* Use whole name otherwise*/
  85.  
  86.     (void) fancy_str (last_name_first);            /* Get caps in where needed */
  87.     namelen = (int) strlen (last_name_first);    /* Calc length now          */
  88.  
  89.     midname[0] = '\0';                            /* "null-terminated string" */
  90.     (void) strcpy (midname, net_info);            /* take nodelist path       */
  91.     (void) strcat (midname, "FIDOUSER.LST");    /* add in the file name     */
  92.  
  93.     if ((f = share_open (midname, O_RDONLY | O_BINARY, DENY_WRITE)) == -1)
  94.     {
  95.         reclength = -1;                               /* Reset all on open failure*/
  96.         return;
  97.     }
  98.  
  99.     /* Find out if we have done this before */
  100.  
  101.     if (reclength == -1)
  102.     {
  103.         /* If not, then determine file size and record length */
  104.  
  105.         (void) stat (midname, &buffer);            /* Get file stats in buffer */
  106.         (void) read (f, midname, 80);            /* Read 1 record            */
  107.         reclength = (int) (strchr (midname, '\n') - midname) + 1;/* FindEnd */
  108.         nrecs = (int) (buffer.st_size / reclength);    /* Get num of records   */
  109.     }
  110.  
  111.     /* Binary search algorithm */
  112.  
  113.     low = 0;
  114.     high = nrecs - 1;
  115.     while (low <= high)
  116.     {
  117.         mid = low + (high - low) / 2;
  118.         (void) lseek (f, (long) ((long) mid * (long) reclength), SEEK_SET);
  119.         (void) read (f, midname, (unsigned int) reclength);
  120.         if ((cond = strnicmp (last_name_first, midname, (unsigned int) namelen)) < 0)
  121.             high = mid - 1;
  122.         else
  123.         {
  124.             if (cond > 0)
  125.                 low = mid + 1;
  126.             else
  127.             {
  128.                 /* Return the address information */
  129.  
  130.                 (void) close (f);
  131.  
  132.                 /* The offset of 40 is just a number that should work properly */
  133.  
  134.                 faddr->Point = 0;
  135.                 if (!find_address (&midname[40], faddr))
  136.                 {
  137.                     faddr->Zone = faddr->Net = faddr->Node = faddr->Point = (unsigned short) -1;
  138.                 }
  139.                 return;
  140.             }
  141.         }
  142.     }
  143.     faddr->Zone = faddr->Net = faddr->Node = faddr->Point = (unsigned short) -1;
  144.     faddr->Domain = NULL;
  145.     (void) close (f);
  146. }
  147.  
  148.